package com.gaoy.springdemo.controller;

import com.gaoy.springdemo.model.UserInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/request")                  //类路径
public class RequestController {
    @RequestMapping("/r1")                   //方法路径
    public String r1(String keyword) {
        return "接收参数:"+keyword;
    }
    @RequestMapping("/r2")
    public String r2(String userName,String password) {
        return "账号:"+userName+"密码:"+password;
    }
    @RequestMapping("/r3")
    public String r3(@RequestParam(value = "q",required = false) String keyword) {
        return "接受参数:keyword"+keyword;
    }
    //传递json
    @RequestMapping("/r9")
    public String r9(@RequestBody UserInfo userInfo){
        return userInfo.toString();
    }
    //从URL中获取参数
    @RequestMapping("/article/{articleId}")
    public String r10( @PathVariable String articleId) {
        return "获取文章ID:"+ articleId;
    }
    //上传文件
    @RequestMapping("r11")
    public String r11(MultipartFile file) throws IOException {
        System.out.println(file.getOriginalFilename());
        return "文件获取成功";
    }

}
